package com.qfedu.mall.api.controller;

import com.qfedu.mall.beans.entity.ShoppingCart;
import com.qfedu.mall.common.vo.ResultVO;
import com.qfedu.mall.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/shopcart")
@CrossOrigin
@Api(value = "提供购物车业务相关接口",tags = "购物车管理")
public class ShopcartController {
    @Autowired
    private ShoppingCartService service;

    @PostMapping("/add")
    @ApiOperation("购物车添加接口")
    public ResultVO addShoppingCary(@RequestBody ShoppingCart cart){
        System.out.println("购物车添加接口cart：" + cart);
        return service.addShoppingCart(cart);
    }


    @GetMapping("/list")
    @ApiOperation("购物车用户商品接口")
    @ApiImplicitParam(dataType = "int",name = "userId", value = "用户id",required = true)
    public ResultVO list(Integer userId){
        System.out.println("userId:" + userId);
        return service.listShoppingCartsByUserId(userId);
    }

    @ApiOperation("购物车内修改商品数量接口")
    @PutMapping("/update/{cid}/{cnum}")
    public ResultVO updateNum(@PathVariable("cid") Integer cartId,@PathVariable("cnum")Integer cartNum){
        return service.updateCartNum(cartId,cartNum);
    }


    @GetMapping("/listbycids")
    @ApiOperation("查询购物车选择商品接口")
    @ApiImplicitParam(dataType = "String",name = "cids", value = "购物车id",required = true)
    public ResultVO listByCids(String cids){
        return service.listShoppingCartByCids(cids);
    }


    @DeleteMapping("/deleteCart")
    @ApiOperation("根据ID删除购物车商品接口")
    @ApiImplicitParam(dataType = "String",name = "cids", value = "购物车商品id",required = true)
    public ResultVO deleteCartById(String cids){
        return service.deleteCartbyCids(cids);
    }


    @PostMapping("/settlement")
    @ApiImplicitParam("购物车结算")
    public ResultVO SettlementCart(Integer cartId){
        System.out.println("cartId:" + cartId);
        ResultVO resultVO = service.settlementCart(cartId);
        return null;
    }




}
